// common/components/fileList/fileList.js
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    list: {
      type: Array,
      value: []
    }
  },

  /**
   * 组件的初始数据
   */
  data: {
    periviewList: [],
    // mockList: [{
    //   id: 62,
    //   name: "eM9v2MI44o2z5414ba3d6099b80ef2fefabb8973f934.mp4",
    //   previewName: "f2fefabb8973f934.mp4",
    //   previewUrl: "http://192.168.2.19:9001/jyw/2023/09/15/b9c03e2d3f124cd29d53476b0a938d6b.mp4",
    //   suffix: "mp4",
    //   url: "2023/09/15/b9c03e2d3f124cd29d53476b0a938d6b.mp4",
    // }, {
    //   id: 63,
    //   name: "QylbuATF5iELb594825630c2131f1065290146b68033.png",
    //   previewName: "1065290146b68033.png",
    //   previewUrl: "http://192.168.2.19:9001/jyw/2023/09/15/eea08bcea4a742d5baa089a8df560281.png",
    //   suffix: "png",
    //   url: "2023/09/15/eea08bcea4a742d5baa089a8df560281.png",
    // }],
    suffixConfig: {
      "jpg": {
        icon: 'image'

      },
      "jpeg": {
        icon: 'image'

      },
      "png": {
        icon: 'image'

      },
      "gif": {
        icon: 'image'

      },
      "bmp": {
        icon: 'image'

      },
      "tiff": {
        icon: 'image'

      },
      "tif": {
        icon: 'image'

      },
      "svg": {
        icon: 'image'
      },
      "mpg": {
        icon: "video"
      },
      "mpeg": {
        icon: "video"
      },
      "avi": {
        icon: "video"
      },
      "mov": {
        icon: "video"
      },
      "wmv": {
        icon: "video"
      },
      "mp4": {
        icon: "video"
      },
      "flv": {
        icon: "video"
      },
      "mkv": {
        icon: "video"
      },
      "3gp": {
        icon: "video"
      },
      "pdf": {
        icon: 'file-pdf'
      },
      "zip": {
        icon: 'file-zip'
      },
      "rar": {
        icon: 'file-zip'
      },
      "7z": {
        icon: 'file-zip'
      },
      "gz": {
        icon: 'file-zip'
      },
      "tar": {
        icon: 'file-zip'
      },
      "tgz": {
        icon: 'file-zip'
      },
      "bz2": {
        icon: 'file-zip'
      },
      "xz": {
        icon: 'file-zip'
      },
      "ppt": {
        icon: 'file-powerpoint'
      },
      "pptx": {
        icon: 'file-powerpoint'
      },
      "doc": {
        icon: "file-word"
      },
      "docx": {
        icon: "file-word"
      },
      "one": {
        icon: "file-onenote"

      },
      "onetoc2": {
        icon: "file-onenote"
      },
      "xls": {
        icon: 'file-excel'
      },
      "xlsx": {
        icon: 'file-excel'
      },
      "xlsm": {
        icon: 'file-excel'
      },
      "csv": {
        icon: 'file-excel'
      },
      'mp3': {
        icon: 'file-musice'
      },
      'wav': {
        icon: 'file-musice'
      },
      'flac': {
        icon: 'file-musice'
      },
      'aac': {
        icon: 'file-musice'
      },
      'ogg': {
        icon: 'file-musice'
      },
      'aiff': {
        icon: 'file-musice'
      },
      'wma': {
        icon: 'file-musice'
      },
      'm4a': {
        icon: 'file-musice'

      }
    },

  },
  observers: {
    list: function (val) {
      if (wx.$_.isArray(val) && val.length) {
        console.log(val, 'pperiviewList');
        let periviewList = this.data.periviewList
        periviewList.push(...val)
        this.setData({
          periviewList: periviewList
        })
      }
    }
  },

  /**
   * 组件的方法列表
   */
  methods: {
    onDel({
      currentTarget
    }) {
      const {
        index
      } = currentTarget.dataset
      const list = this.data.periviewList
      list.splice(index, 1)
      console.log('onDel');
      this.setData({
        periviewList: list
      })
      this.triggerEvent('onDelFileList', {
        value: list
      })
    },
    onFileItem({
      currentTarget
    }) {
      // console.log(e, 'tempFilePath')
      const {
        index
      } = currentTarget.dataset
      console.log(this.data.periviewList);

      wx.previewMedia({
        sources: this.data.periviewList.map((item) => {
          return {
            url: item.previewUrl,
          }
        }),
        current: index,
        success(res) {
          console.log('成功', res);
        },
        fail(err) {
          console.log('失败', err);
        }
      })
    }
  }
})